using System.Drawing;

namespace RivercrabNet
{
    public class CandleShape : BaseShape
    {
        private Color _closeTitleColor = Color.Yellow;
        private string _colorFlag = ("CandleShape.UpDownFlag." + Common.GetGuid());
        private string[] _displayName = new[] {"OPEN", "HIGH", "LOW", "CLOSE"};
        private bool _displayTitleField = true;
        private Brush _downLineBrush;
        private Pen _downLinePen;
        private Color _downColor;
        private Color _highTitleColor = Color.Red;
        private Color _lowTitleColor = Color.Orange;
        private Pen _middleDownLinePen = new Pen(Color.White);
        private Color _middleDownColor = Color.White;
        private Pen _middleUpLinePen = new Pen(Color.White);
        private Color _middleUpColor = Color.White;
        private Color _openTitleColor = Color.White;
        private Brush _upLineBrush;
        private Pen _upLinePen;
        private Brush _upLineTransparentBrush;
        private Color _upColor;

        public CandleStyle CandleStyle { get; set; }

        public string CloseField { get; set; }

        public Color CloseTitleColor
        {
            get { return _closeTitleColor; }
            set { _closeTitleColor = value; }
        }

        public string ColorFlag
        {
            get { return _colorFlag; }
            set { _colorFlag = value; }
        }

        public bool CrossFlag { get; set; }

        public string[] DisplayName
        {
            get { return _displayName; }
            set { _displayName = value; }
        }

        public bool DisplayTitleField
        {
            get { return _displayTitleField; }
            set { _displayTitleField = value; }
        }

        public Color DownColor
        {
            get { return _downColor; }
            set
            {
                _downColor = value;
                if (_downLineBrush != null)
                {
                    _downLineBrush.Dispose();
                }
                _downLineBrush = new SolidBrush(value);
                if (_downLinePen != null)
                {
                    _downLinePen.Dispose();
                }
                _downLinePen = new Pen(value);
            }
        }

        public Brush DownLineBrush
        {
            get { return _downLineBrush; }
            set { _downLineBrush = value; }
        }

        public Pen DownLinePen
        {
            get { return _downLinePen; }
            set { _downLinePen = value; }
        }

        public string HighField { get; set; }

        public Color HighTitleColor
        {
            get { return _highTitleColor; }
            set { _highTitleColor = value; }
        }

        public string LowField { get; set; }

        public Color LowTitleColor
        {
            get { return _lowTitleColor; }
            set { _lowTitleColor = value; }
        }

        public int MaxRecord { get; set; }

        public Color MiddleDownColor
        {
            get { return _middleDownColor; }
            set
            {
                _middleDownColor = value;
                if (_middleDownLinePen != null)
                {
                    _middleDownLinePen.Dispose();
                }
                _middleDownLinePen = new Pen(value);
            }
        }

        public Pen MiddleDownLinePen
        {
            get { return _middleDownLinePen; }
            set { _middleDownLinePen = value; }
        }

        public Color MiddleUpColor
        {
            get { return _middleUpColor; }
            set
            {
                _middleUpColor = value;
                if (_middleUpLinePen != null)
                {
                    _middleUpLinePen.Dispose();
                }
                _middleUpLinePen = new Pen(value);
            }
        }

        public Pen MiddleUpLinePen
        {
            get { return _middleUpLinePen; }
            set { _middleUpLinePen = value; }
        }

        public int MinRecord { get; set; }

        public string OpenField { get; set; }

        public Color OpenTitleColor
        {
            get { return _openTitleColor; }
            set { _openTitleColor = value; }
        }

        public Color UpColor
        {
            get { return _upColor; }
            set
            {
                _upColor = value;
                if (_upLineBrush != null)
                {
                    _upLineBrush.Dispose();
                }
                _upLineBrush = new SolidBrush(value);
                if (_upLinePen != null)
                {
                    _upLinePen.Dispose();
                }
                _upLinePen = new Pen(value);
                if (_upLineTransparentBrush != null)
                {
                    _upLineTransparentBrush.Dispose();
                }
                _upLineTransparentBrush = new SolidBrush(Color.FromArgb(100, value));
            }
        }

        public Brush UpLineBrush
        {
            get { return _upLineBrush; }
            set { _upLineBrush = value; }
        }

        public Pen UpLinePen
        {
            get { return _upLinePen; }
            set { _upLinePen = value; }
        }

        public Brush UpLineTransparentBrush
        {
            get { return _upLineTransparentBrush; }
            set { _upLineTransparentBrush = value; }
        }

        ~CandleShape()
        {
            if (_upLineBrush != null)
            {
                _upLineBrush.Dispose();
            }
            if (_downLineBrush != null)
            {
                _downLineBrush.Dispose();
            }
            if (_middleUpLinePen != null)
            {
                _middleUpLinePen.Dispose();
            }
            if (_middleDownLinePen != null)
            {
                if (_middleUpLinePen != null) 
                    _middleUpLinePen.Dispose();
            }
            if (_upLinePen != null)
            {
                _upLinePen.Dispose();
            }
            if (_upLineTransparentBrush != null)
            {
                _upLineTransparentBrush.Dispose();
            }
            if (_downLinePen != null)
            {
                _downLinePen.Dispose();
            }
        }
    }
}